package lerry.nape.factory;
	import nape.callbacks.CbEvent;
	import nape.callbacks.CbType;
	import nape.callbacks.InteractionCallback;
	import nape.callbacks.InteractionListener;
	import nape.callbacks.InteractionType;
	import nape.phys.Body;
	import nape.phys.BodyList;
	import nape.space.Space;

	class ListenerFactory {
		public static function bodyToBody(body1:Body, body2:Body, callBack:InteractionCallback->Void=null, space:Space=null):InteractionListener {
			var cb1:CbType=new CbType();
			var cb2:CbType=new CbType();
			body1.cbTypes.add(cb1);
			body2.cbTypes.add(cb2);
			var listener:InteractionListener=new InteractionListener(CbEvent.ONGOING, InteractionType.COLLISION, cb1, cb2, callBack);
			if (space!=null)
				listener.space=space;
			return listener;
		}

		public static function bodyToBodies(body:Body, bodies:BodyList, callBack:InteractionCallback->Void=null, space:Space=null):Void {
			var cb1:CbType=new CbType();
			body.cbTypes.add(cb1);
			var len:UInt=bodies.length;
			if (len == 0)
				return;
			for (i in 0...len) {
				var cb:CbType=new CbType();
				bodies.at(i).cbTypes.add(cb);
				var listener:InteractionListener=new InteractionListener(CbEvent.BEGIN, InteractionType.COLLISION, cb1, cb,callBack);
				listener.space=space;
			}
		}

		public static function bodiesToBodies(bodies1:BodyList, bodies2:BodyList, callBack:InteractionCallback->Void=null, space:Space=null):Void {
			var len1:UInt=bodies1.length;
			var len2:UInt=bodies2.length;
			if (len1 == 0 || len2 == 0)
				return;
			for (i in 0...len1) {
				var cb1:CbType=new CbType();
				bodies1.at(i).cbTypes.add(cb1);
				for (j in 0...len2) {
					var cb2:CbType=new CbType();
					bodies2.at(j).cbTypes.add(cb2);
					var listener:InteractionListener=new InteractionListener(CbEvent.BEGIN, InteractionType.COLLISION, cb1, cb2, callBack);
					listener.space=space;
				}
			}
		}
	} //end class
